﻿using BLL.Interface;
using Common.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model;
using Model.DTO.Public.GetList;
using Model.DTO.Public.OperateId;
using Model.DTO.User;
using System.Data;

namespace TianXiaHuiForumManagementSystem.Controllers.Admin
{
    [Route("Admin/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserBLL _userBLL;
        public UserController(IUserBLL userBLL)
        {
            _userBLL = userBLL;
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("AddUser")]
        public async Task<string> AddUser(AddUserDTO param)
        {
            var result = await _userBLL.AddUser(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 编辑用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("EditUser")]
        public async Task<string> EditUser(EditUserDTO param)
        {
            var result = await _userBLL.EditUser(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("GetUserList")]
        public async Task<string> GetUserList(GetListDTO param)
        {
            var result = await _userBLL.GetUserList(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("Login")]
        public async Task<string> Login(UserLoginDTO param)
        {
            var result = await _userBLL.Login(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("Register")]
        public async Task<string> Register(UserRegisterDTO param)
        {
            var result = await _userBLL.Register(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost, Route("GetUserInfo")]
        public async Task<string> GetUserInfo(string? token)
        {
            var result = await _userBLL.GetUserInfo(token);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 登出
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("Logout")]
        public async Task<string> Logout()
        {
            return await Task.FromResult(ResponseMessage.CreateSuccess("登出成功").ToJsonFormat());
        }
        /// <summary>
        /// 禁用用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("BanUser")]
        [Authorize(Roles = "Admin")]
        public async Task<string> BanUser(OperateIdDTO_INT param)
        {
            var result = await _userBLL.BanUser(param);
            return result.ToJsonFormat();
        }
        /// <summary>
        /// 绑定用户类型
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("BindUserTypes")]
        [Authorize(Roles = "Admin")]
        public async Task<string> BindUserTypes(OperateIdDTO_INT param)
        {
            var result = await _userBLL.BindUserTypes(param);
            return result.ToJsonFormat();
        }
    }
}
